﻿Public Class CharCodeArgHandler
    Implements IArgHandler

    Public Function GetValues(obj As RawObject, argument As ArgumentDefinition) As System.Collections.Generic.IEnumerable(Of String) Implements IArgHandler.GetValues
        Return New List(Of String)
    End Function

    Public Function ValidateArgument(library As RawLibrary, obj As RawObject, argument As ArgumentDefinition, value As String) As String Implements IArgHandler.ValidateArgument
        Dim intVal As Integer
        If Integer.TryParse(value, intVal) Then
            'test if in range of 0 to 255
            If intVal < 0 OrElse intVal > 255 Then
                Return "Value must be between 0 and 255"
            End If

            Return Nothing
        Else
            'test to make sure it is a single char enclosed in single quotes
            If value.Length <> 3 Then
                Return "Value must be a single character enclosed in single-quotes"
            End If

            If Not value.StartsWith("'") OrElse Not value.EndsWith("'") Then
                Return "Value must be a single character enclosed in single-quotes"
            End If

            Dim ascii As Integer = Convert.ToInt32(value(1))
            If ascii < 0 OrElse ascii > 255 Then
                Return "Value must be character with an ASCII code between 0 and 255"
            End If

            Return Nothing
        End If
    End Function

    Public Function ValidateTypeData(typeData As String) As Boolean Implements IArgHandler.ValidateTypeData
        Return True
    End Function

    Public ReadOnly Property TypeDataFormat As String Implements IArgHandler.TypeDataFormat
        Get
            Return ""
        End Get
    End Property

    Public ReadOnly Property DefaultTypeData As String Implements IArgHandler.DefaultTypeData
        Get
            Return ""
        End Get
    End Property

    Public ReadOnly Property DefaultValue(library As RawLibrary, obj As RawObject, argument As ArgumentDefinition) As String Implements IArgHandler.DefaultValue
        Get
            Return "'a'"
        End Get
    End Property

    Public Function Parse(argParts As System.Collections.Generic.IEnumerator(Of String), arg As ArgumentDefinition) As String Implements IArgHandler.Parse
        Return argParts.Current
    End Function

    Public Function GetNavList(library As RawLibrary, obj As RawObject, argument As ArgumentDefinition, value As String) As IEnumerable(Of NavPoint) Implements IArgHandler.GetNavList
        Return Nothing
    End Function
End Class
